package com.company;

import java.sql.*;
import java.util.ArrayList;
import java.util.List;

public class Dao {

	private static String driver = "oracle.jdbc.driver.OracleDriver";
	private static String url = "jdbc:oracle:thin:@localhost:1521:XE";
	private static String user="hr";
	private static String password="123456";
	public static final int k = 7;
	public List<Object[]> selectAll() throws SQLException {
		List<Object[]> ls = new ArrayList<Object[]>();
		// 省略连接数据库和获取数据
			Connection conn = DriverManager.getConnection(url, user, password);//连接数据库
			PreparedStatement pst = conn.prepareStatement("select * from student");//准备执行SQL语句
			ResultSet rs = pst.executeQuery();
			int sample = 0;
			while (rs.next()) {
				sample++;
			}
			String[][] stu = new String[sample][k];
			rs = pst.executeQuery();
			for (int i = 0; rs.next(); i++) {
				for (int j = 0; j < k; j++) {
					stu[i][j] = rs.getString(j + 1);
				}
				ls.add(stu[i]);
			}

			rs.close();//数据库先开后关
			pst.close();
			conn.close();//关闭数据库
		return ls;
	}
	
}
